#include "StomperLib/Controls/ToolSet.h"
#include <iostream>
namespace StomperLib {
namespace Controls
{
GWEN_CONTROL_CONSTRUCTOR( ToolSet )
{
  SetColumnCount( 4 );
  SetColumnWidth( 0, 27 );
  SetColumnWidth( 1, 27 );
  SetColumnWidth( 2, 27 );
  SetColumnWidth( 3, 27 );
  Dock( Gwen::Pos::Fill );
  this->m_ToggleButtons = std::vector<Gwen::Controls::Button*>( );
}
void ToolSet::InitRows( int numberOfRows )
{
  for (int i = 0; i < numberOfRows; ++i)
  {
    this->AddRow( );
  }
}

Gwen::Controls::Button* ToolSet::AddButton( Gwen::String name, Gwen::String image, Gwen::String toolTip, int row,
                                            int column,
                                            bool isToggle )
{
  Gwen::Controls::Button* button = new Gwen::Controls::Button( this );
  button->SetName( name );
  button->SetImage( image );
  button->SetToolTip( toolTip );
  button->SetSize( 25, 25 );
  if (isToggle)
  {
    button->SetIsToggle( true );
    button->onToggleOn.Add( this, &ToolSet::OnToogleChange );
    this->m_ToggleButtons.push_back( button );
  }
  this->GetRow( row )->SetCellContents( column, button );
  return button;
}

void ToolSet::OnToogleChange( Gwen::Event::Info info )
{
  for (auto tButton = this->m_ToggleButtons.begin( ); tButton != this->m_ToggleButtons.end( ); ++tButton)
  {
    if (*tButton == info.Control)
      continue;
    else if ((*tButton)->GetToggleState( ))
    {
      (*tButton)->SetToggleState( false );
    }
  }
}

}
}